$(function() {
    let form = layui.form
    form.verify({
        pwd: [
            /^[\S]{6,12}$/,
            '密码必须为6到12位，且不能有空格'
        ],
        newPwd: function(value) {
            let v = $('[name=oldPwd]').val()
            if (v == value) {
                return '新密码不能与旧密码一致'
            }
        },
        renewPwd: function(value) {
            let v = $('[name=newPwd]').val()
            if (v !== value) {
                return '两次密码不一致'
            }
        }

    })

    $('form').on('submit', function(e) {
        e.preventDefault()
        axios({
            method: 'POST',
            url: '/my/updatepwd',
            data: $(this).serialize()
        }).then(({ data: res }) => {
            console.log(res);
            if (res.status != 0) {
                return layer.msg(res.message)
            }
            layer.msg(res.message)
            setTimeout(function() {
                window.parent.location.href = '/login.html'
                localStorage.removeItem('token')
            }, 1500)
        })
    })



})